$(document).ready(function() {
						//表单验证
						$(".addForm").validate({
							onfocusout : function(element) {
								$(element).valid();
							},
							rules : {
								name : "required",
								color : "required",
								description : "required"
							},
							messages : {
								name : "请输入作品名称",
								color : "请输入色彩",
								description : "请输入描述内容"
							}
						});
						$(".imghead").each(function(index) {
							$(this).click(function() {
								$(".tohide")[index].click();

							});
						});
						//图片上传预览    IE是用了滤镜。
						$("input[class='file']")
								.each(
										function(index) {
											function previewImage(file) {
												var MAXWIDTH = 260;
												var MAXHEIGHT = 180;
												var div = $('.preview')[index];
												if (file.files
														&& file.files[index]) {
													div.innerHTML = '<img class=imghead>';
													var img = $('.imghead')[index];
													img.onload = function() {
														var rect = clacImgZoomParam(
																MAXWIDTH,
																MAXHEIGHT,
																img.offsetWidth,
																img.offsetHeight);
														img.width = rect.width;
														img.height = rect.height;
														img.style.marginTop = rect.top
																+ 'px';
													}
													var reader = new FileReader();
													reader.onload = function(
															evt) {
														img.src = evt.target.result;

													}
													reader
															.readAsDataURL(file.files[index]);
												} else //兼容IE
												{
													var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
													file.select();
													var src = document.selection
															.createRange().text;
													div.innerHTML = '<img class=imghead>';
													var img = $('.imghead')[index];
													img.filters
															.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
													var rect = clacImgZoomParam(
															MAXWIDTH,
															MAXHEIGHT,
															img.offsetWidth,
															img.offsetHeight);
													status = ('rect:'
															+ rect.top + ','
															+ rect.left + ','
															+ rect.width + ',' + rect.height);
													div.innerHTML = "<div class=divhead style='width:" + rect.width + "px;height:" + rect.height + "px;margin-top:" + rect.top + "px;" + sFilter + src + "\"'></div>";
												}
											}

											function clacImgZoomParam(maxWidth,
													maxHeight, width, height) {
												var param = {
													top : 0,
													left : 0,
													width : width,
													height : height
												};
												if (width > maxWidth
														|| height > maxHeight) {
													rateWidth = width
															/ maxWidth;
													rateHeight = height
															/ maxHeight;
													if (rateWidth > rateHeight) {
														param.width = maxWidth;
														param.height = Math
																.round(height
																		/ rateWidth);
													} else {
														param.width = Math
																.round(width
																		/ rateHeight);
														param.height = maxHeight;
													}
												}
												param.left = Math
														.round((maxWidth - param.width) / 2);
												param.top = Math
														.round((maxHeight - param.height) / 2);
												return param;
											}
										});
						//图片上传
						$("input[type='file']")
								.change(
										function() {
											var imgObjPreview = $(this)
													.parent().find("img");
											console.log($(this).prop("files"));
											if ($(this).prop("files")
													&& $(this).prop("files")[0]) {
												imgObjPreview
														.attr(
																"src",
																window.URL
																		.createObjectURL($(
																				this)
																				.prop(
																						"files")[0]));
												if ($(this).prev().find(
														".imghead").attr("src") != "") {
													$(this)
															.prev()
															.find(".select")
															.addClass(
																	"changesel");
													$(this)
															.prev()
															.find(".select")
															.text(
																	"重新"
																			+ $(
																					this)
																					.prev()
																					.find(
																							".select")
																					.text());

												}
											} else {
												//IE下，使用滤镜
												docObj.select();
												var imgSrc = document.selection
														.createRange().text;
												var localImagId = document
														.getElementById("localImag");
												//必须设置初始大小
												localImagId.style.width = "150px";
												localImagId.style.height = "180px";
												//图片异常的捕捉，防止用户修改后缀来伪造图片
												try {
													localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
													localImagId.filters
															.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
												} catch (e) {
													alert("您上传的图片格式不正确，请重新选择!");
													return false;
												}
												imgObjPreview.style.display = 'none';
												document.selection.empty();
											}
											return true;
										});
	//分类中类					
	$("#big_class").change(function(){
		var parent_code = $(this).val();
		
		$.ajax({
			url:'getClothing_class.do',
			data:'parent_code='+parent_code,
			success:function(data){
				$("#middle_class").empty();
				$("#middle_class").append("<option value='-1'>请选择中类</option>");
				$.each(data,function(n,item){
					var result="";
					result+="<option"+" value="+"'"+item.code+"'"+">"+item.name+"</option>";
					$("#middle_class").append(result);
				})
					
				
			}
		})
	});
	//分类小类
	$("#middle_class").change(function(){
		var parent_code = $(this).val();
		$.ajax({
			url:'getClothing_class.do',
			data:'parent_code='+parent_code,
			success:function(data){
				$("#small_class").empty();
				$("#small_class").append("<option value='-1'>请选择小类</option>");
				$.each(data,function(n,item){
					var result="";
					result+="<option"+" value="+"'"+item.code+"'"+">"+item.name+"</option>";
					$("#small_class").append(result);
				})
			}
		})
	});
	//面料小类
	$("#parent_class").change(function(){
		var parent_code = $(this).val();
		$.ajax({
			url:'getFabric_small_class.do',
			data:'parent_code='+parent_code,
			success:function(data){
				$("#child_class").empty();
				$("#child_class").append("<option value='-1'>请选择小类</option>");
				$.each(data,function(n,item){
					var result="";
					result+="<option"+" value="+"'"+item.code+"'"+">"+item.name+"</option>";
					$("#child_class").append(result);
				})
			}
		})
	});
	
})